package com.zjcloud.jwgl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zjcloud.common.annotation.Log;
import com.zjcloud.common.core.controller.BaseController;
import com.zjcloud.common.core.domain.AjaxResult;
import com.zjcloud.common.enums.BusinessType;
import com.zjcloud.jwgl.domain.AcScheduleConstraint;
import com.zjcloud.jwgl.service.IAcScheduleConstraintService;
import com.zjcloud.common.utils.poi.ExcelUtil;
import com.zjcloud.common.core.page.TableDataInfo;

/**
 * 排课约束条件Controller
 * 
 * @author wxl
 * @date 2024-09-13
 */
@RestController
@RequestMapping("/jwgl/constraint")
public class AcScheduleConstraintController extends BaseController {
    @Autowired
    private IAcScheduleConstraintService acScheduleConstraintService;

    /**
     * 查询排课约束条件列表
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:constraint:list')")
    @GetMapping("/list")
    public TableDataInfo list(AcScheduleConstraint acScheduleConstraint) {
        startPage();
        List<AcScheduleConstraint> list = acScheduleConstraintService.selectAcScheduleConstraintList(acScheduleConstraint);
        return getDataTable(list);
    }

    /**
     * 导出排课约束条件列表
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:constraint:export')")
    @Log(title = "排课约束条件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AcScheduleConstraint acScheduleConstraint) {
        List<AcScheduleConstraint> list = acScheduleConstraintService.selectAcScheduleConstraintList(acScheduleConstraint);
        ExcelUtil<AcScheduleConstraint> util = new ExcelUtil<AcScheduleConstraint>(AcScheduleConstraint.class);
        util.exportExcel(response, list, "排课约束条件数据");
    }

    /**
     * 获取排课约束条件详细信息
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:constraint:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(acScheduleConstraintService.selectAcScheduleConstraintById(id));
    }

    /**
     * 新增排课约束条件
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:constraint:add')")
    @Log(title = "排课约束条件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AcScheduleConstraint acScheduleConstraint) {
        return toAjax(acScheduleConstraintService.insertAcScheduleConstraint(acScheduleConstraint));
    }

    /**
     * 修改排课约束条件
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:constraint:edit')")
    @Log(title = "排课约束条件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AcScheduleConstraint acScheduleConstraint) {
        return toAjax(acScheduleConstraintService.updateAcScheduleConstraint(acScheduleConstraint));
    }

    /**
     * 删除排课约束条件
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:constraint:remove')")
    @Log(title = "排课约束条件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(acScheduleConstraintService.deleteAcScheduleConstraintByIds(ids));
    }
    
    /**
     * 获取指定学期的启用约束条件
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:constraint:list')")
    @GetMapping("/enabled/{semester}")
    public AjaxResult getEnabledConstraints(@PathVariable("semester") String semester) {
        return success(acScheduleConstraintService.getEnabledConstraints(semester));
    }
    
    /**
     * 批量更新约束条件权重
     */
    // @PreAuthorize("@ss.hasPermi('jwgl:constraint:edit')")
    @Log(title = "更新约束权重", businessType = BusinessType.UPDATE)
    @PutMapping("/weights")
    public AjaxResult updateWeights(@RequestBody List<AcScheduleConstraint> constraints) {
        return toAjax(acScheduleConstraintService.updateConstraintWeights(constraints));
    }
}